Skip to content

Fix/xiao long#73

Closed
xji650 wants to merge 11 commits intoUdL-EPS-SoftArch-Igualada:mainfrom
UdL-Arch-Software-Empresite:fix/XiaoLong
Closed

Fix/xiao long#73
xji650 wants to merge 11 commits intoUdL-EPS-SoftArch-Igualada:mainfrom
UdL-Arch-Software-Empresite:fix/XiaoLong

Conversation

@xji650
Copy link
Contributor

@xji650 xji650 commented Mar 4, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 4, 2026 00:35
@udl-softarch
Copy link

udl-softarch bot commented Mar 4, 2026

Hi @xji650, this PR is not linked to any issue.
Please link it by editing the PR description and adding something like:

Closes #123

@udl-softarch udl-softarch bot added the pr-missing-linked-issue This PR needs to be linked to an in-progress task label Mar 4, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0051630 and e8bc4ad.

📒 Files selected for processing (4)
  • src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java
  • src/main/java/cat/udl/eps/softarch/fll/domain/Match.java
  • src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java
  • src/main/java/cat/udl/eps/softarch/fll/domain/Round.java

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Refactor
    • Enhanced data validation and consistency across competition, match, and referee relationships.
    • Strengthened enforcement of constraints, including a maximum of 3 referees per competition table.
    • Improved bidirectional synchronization to ensure data integrity when managing matches and referees.

Walkthrough

This PR refactors four domain entities to use Lombok-based boilerplate generation, replacing explicit getter/setter methods with @Getter, @Setter, and @NoArgsConstructor annotations. It also enhances relationship management in CompetitionTable and Round with new public APIs that enforce defensive null checks and bidirectional synchronization, along with cascade behavior adjustments and lazy loading specifications.

Changes

Cohort / File(s) Summary
Relationship management API
src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java, src/main/java/cat/udl/eps/softarch/fll/domain/Round.java
Introduced public methods for managing matches and referees (addMatch, removeMatch, setMatches, addReferee, removeReferee, setReferees) with defensive null checks, deduplication, and bidirectional synchronization. Changed Match cascade from CascadeType.ALL to {CascadeType.PERSIST, CascadeType.MERGE} in CompetitionTable. Restricted direct field mutation via Lombok-generated NONE setters.
Lombok boilerplate refactoring
src/main/java/cat/udl/eps/softarch/fll/domain/Match.java, src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java
Replaced explicit getter/setter methods and constructors with Lombok annotations (@Getter, @Setter, @NoArgsConstructor, @EqualsAndHashCode). Added @EqualsAndHashCode.Include to id field in Match. Added lazy loading specification to supervisesTable relation in Referee via @ManyToOne(fetch = FetchType.LAZY).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • #57: Adds teamA/teamB fields to Match.java, which may conflict with the Lombok boilerplate refactoring in this PR.
  • #42: Modifies Match and Referee domain entities with relationship-handling logic that overlaps with the relationship management changes in this PR.

Suggested labels

pr-not-ready


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors several JPA domain entities to reduce boilerplate by adopting Lombok-generated accessors/constructors and adjusts entity relationship helper methods to better manage bidirectional associations (including null/duplicate handling).

Changes:

  • Replace explicit constructors/getters/setters with Lombok annotations (@Getter, @Setter, @NoArgsConstructor) across multiple entities.
  • Add/adjust equals/hashCode generation via Lombok, primarily including entity identifiers.
  • Update add/remove helpers for Round and CompetitionTable to handle nulls, de-duplication, and moving children between parents; adjust cascade settings for table→matches.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/main/java/cat/udl/eps/softarch/fll/domain/Round.java Lombok refactor + updated match association helpers
src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java Lombok refactor + Lombok equals/hashCode configuration
src/main/java/cat/udl/eps/softarch/fll/domain/Match.java Lombok refactor + newly introduced equals/hashCode on generated id
src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java Lombok refactor + updated match/referee association helpers + cascade change

Comment on lines 47 to +54
public void addMatch(Match match) {
if (match == null) {
return;
}

if (matches.contains(match)) {
return;
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addMatch uses matches.contains(match) to prevent duplicates, but Match now has Lombok equals/hashCode based only on the generated id. For transient matches (where id == null), all instances compare equal, so adding multiple new Match() objects will be incorrectly blocked (and removeMatch may remove the wrong instance). Consider changing the duplicate check to use object identity when id is null, or revising Match.equals/hashCode so entities with null ids are not considered equal.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to 29
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
public class Match extends UriEntity<Long> {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EqualsAndHashCode includes only the generated id. When id is null (common before persistence), different Match instances will compare equal and share the same hash code. This can break collection operations (e.g., List.contains/remove) and is currently observable via Round.addMatch/CompetitionTable.addMatch duplicate checks. Consider implementing an equality strategy that does not treat two transient entities as equal (e.g., only compare ids when both are non-null).

Copilot uses AI. Check for mistakes.
Comment on lines +47 to 50
public void addMatch(Match match) {
if (match == null || matches.contains(match)) {
return;
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addMatch relies on matches.contains(match) for de-duplication, but Match.equals/hashCode is based solely on a generated id. This makes all transient matches (id == null) appear equal, so adding multiple new matches to a table can be silently skipped and removeMatch may remove an unintended instance. Use an identity-based duplicate check for transient entities or adjust Match.equals/hashCode to avoid null-id equality.

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +79
public void addReferee(Referee referee) {
if (referee == null || referees.contains(referee)) {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addReferee uses referees.contains(referee) to prevent duplicates. Since Referee equality comes from Volunteer and is based on a generated id, two new Referee() instances (with id == null) will compare equal and the second one will be dropped. If you need duplicate prevention, consider checking duplicates by object identity when id is null (or only by id when non-null).

Suggested change
public void addReferee(Referee referee) {
if (referee == null || referees.contains(referee)) {
private boolean isRefereeAlreadyAssigned(Referee referee) {
if (referee == null) {
return false;
}
Object refereeId = referee.getId();
if (refereeId == null) {
for (Referee existingReferee : referees) {
if (existingReferee == referee) {
return true;
}
}
return false;
}
for (Referee existingReferee : referees) {
if (refereeId.equals(existingReferee.getId())) {
return true;
}
}
return false;
}
public void addReferee(Referee referee) {
if (referee == null || isRefereeAlreadyAssigned(referee)) {

Copilot uses AI. Check for mistakes.
Comment on lines 40 to 45
@@ -58,12 +45,30 @@ public void setMatches(List<Match> matches) {
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMatches clears this.matches without updating the owning side (Match.round). This can leave previously associated Match instances still pointing to this Round, breaking bidirectional consistency and potentially confusing JPA orphan removal. Prefer iterating over a copy and calling removeMatch for each existing match before adding the new ones.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-missing-linked-issue This PR needs to be linked to an in-progress task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants